* This file will replicate the analysis for the Colorado Experiment
* Save all files starting with "co_" into a folder and set that folder 
* as the working directory to successfully execute the file.

* Pull in list of individuals from list who were matched as voters and re-save for merging
import delimited "co_gen_voters_wid.csv", clear
sort subject
save voterstomerge, replace

* Pull in list of individuals from list who had previously voted and re-save for merging
import delimited "co_gen_prevvoted_wid.csv", clear
sort subject
save genprevvotedtomerge, replace

* Pull in list of individuals from list and their gender and ideology 
import delimited "co_all_gender_ideology.csv", clear
sort subject
save gendertomerge, replace

* Pull in list of individuals from list and their race and age
import delimited "co_all_race_age.csv", clear
sort subject
save racetomerge, replace

* Pull in list of individuals from list and their partisanship score
import delimited "co_all_partisanship.csv", clear
sort subject
save partisanshiptomerge, replace

* Pull in master list of individuals contacted and then merge in supplementary data from Catalist
import delimited "co_pledge_id.csv", clear
sort subject

merge 1:1 subject using gendertomerge
sort subject
drop _m
merge 1:1 subject using co_canvassers
sort subject
drop _m
merge 1:1 subject using racetomerge
sort subject
drop _m
merge 1:1 subject using partisanshiptomerge
sort subject
drop _m
merge 1:1 subject using voterstomerge

* Create indicator for whether individual voted (based on whether they appeared on Catalist list of voters)
recode _m 3=1 1=0, gen(voted)
drop _m

* Recode variables from Catalist files
gen votepropensity=voteprop1 if voteprop1~=.
replace votepropensity=voteprop2 if voteprop2~=.
replace votepropensity=voteprop3 if voteprop3~=.

replace female=0 if male==1

gen age=age1 if age1~=.
replace age=age2 if age2~=.
replace age=age3 if age3~=.
replace age=age4 if age4~=.
replace age=age5 if age5~=.

gen race=1 if caucasian==1
replace race=2 if black==1
replace race=3 if hispanic==1
replace race=4 if asian==1

* Merge in the list of individuals who had previously voted according to Catalist
sort subject
merge 1:1 subject using genprevvotedtomerge

* Generate indicator for whether individual had previously voted
recode _m 3=0, gen(nevervoted)
drop _m

* Create a numerical indicator for whether individual was in treatment or control group
encode condition, gen(pledged)

* Generate an indicator of the date and condition for each individual (for clustered standard errors)
egen datecond=concat(contact_date condition)
encode datecond, gen(group)

* Generate an indicator of the date and canvasser for each individual (for clustered standard errors)
egen datecanvasser=concat(contact_date canvassedby)
encode datecanvasser, gen(group2)

**** TABLE 3 RESULTS ****

* Table 3, Line 1
* Difference of proportions tests for all individuals regardless of state of residence (with clustered standard errors for shift)
proportion voted, over(pledged) vce(cluster group2)
test [_prop_2]_subpop_2=[_prop_2]_subpop_1

* Table 3, Line 2
* Difference of proportions tests for CO (with clustered standard errors for shift)
proportion voted if state=="CO", over(pledged) vce(cluster group2)
test [_prop_2]_subpop_2=[_prop_2]_subpop_1

* Table 3, Line 3
proportion voted if nevervoted==1 & state=="CO", over(pledged) vce(cluster group2)
test [_prop_2]_subpop_2=[_prop_2]_subpop_1

* OLS Regression of vote choice, incorporating interaction for whether R previously voted
* (Reported in text)
reg voted pledged##nevervoted if state=="CO", vce(cluster group2)

* Model controlling for canvasser
areg voted pledged, absorb(canvassedby) vce(cluster group2)

**** RESULTS IN SUPPORTING INFORMATION ****

* S1 Table Results, Column 2 Line 1
areg voted pledged if state=="CO", absorb(canvassedby) vce(cluster group2)

* S1 Table Results, Column 2 Line 1
areg voted pledged if nevervoted==1 & state=="CO", absorb(canvassedby) vce(cluster group2)

* S2 Table Results, Column 2
* Only individuals below the age of 30
reg voted pledged if (age<30 | age==.), vce(cluster group2)

